package com.iknow.view;

import android.content.Context;
import android.content.IntentFilter;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;
import com.iknow.IKnow;
import com.iknow.app.IKnowSystemConfig;
import com.iknow.ui.model.IKPageAdapter;
import java.text.DecimalFormat;
import java.util.Map;

public class IKPageViewRender
  implements AbsListView.OnScrollListener
{
  private View.OnClickListener FavButtonClickListener;
  protected IKPageAdapter adapter = null;
  protected TextView chapNameView;
  protected String chapterName;
  private boolean mBShowCommant;
  public PopupWindow mChapterWindow = null;
  private Button mCommentsBtn;
  private Context mContext;
  public ViewGroup mHeader;
  protected ListView mListView;
  private String mPid;
  protected TextView progressView = null;

  public IKPageViewRender(Context paramContext)
  {
    this.chapterName = null;
    this.mListView = null;
    this.chapNameView = null;
    this.mCommentsBtn = null;
    this.FavButtonClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
      }
    };
    this.mContext = paramContext;
  }

  public void RegisterBatteryReceiver()
  {
    new IntentFilter().addAction("android.intent.action.BATTERY_CHANGED");
  }

  public void SetShowCommentPage(boolean paramBoolean)
  {
    this.mBShowCommant = false;
  }

  public void addPageMenu(FrameLayout paramFrameLayout)
  {
  }

  public boolean bShowCommentPage()
  {
    return this.mBShowCommant;
  }

  public ListView getListView()
  {
    return this.mListView;
  }

  public void initView(ListView paramListView)
  {
    paramListView.setDivider(null);
    paramListView.setBackgroundColor(IKnow.mSystemConfig.getBook_BackGround());
    paramListView.setCacheColorHint(0);
    paramListView.addHeaderView(this.mHeader);
    RegisterBatteryReceiver();
    paramListView.setOnScrollListener(this);
  }

  public void onCreate()
  {
    initView(getListView());
  }

  public void onDestroy()
  {
    if (this.adapter != null)
      this.adapter.onDestroy();
    if (this.mListView != null)
      this.mListView.setAdapter(null);
    this.adapter = null;
    this.progressView = null;
    this.chapterName = null;
    this.mListView = null;
    this.chapNameView = null;
  }

  public void onLoad(Object paramObject, String paramString, Map<String, String> paramMap)
  {
  }

  public void onScroll(AbsListView paramAbsListView, int paramInt1, int paramInt2, int paramInt3)
  {
    String str = "0%";
    if (paramInt3 != 0)
    {
      float f = (float)(100.0D / paramInt3);
      int i = paramInt1 + paramInt2;
      DecimalFormat localDecimalFormat = new DecimalFormat("#.##");
      if (i >= paramInt3)
        break label84;
      str = localDecimalFormat.format(f * i) + "%";
    }
    while (true)
    {
      this.progressView.setText(str);
      return;
      label84: str = "100%";
    }
  }

  public void onScrollStateChanged(AbsListView paramAbsListView, int paramInt)
  {
  }

  public void onStop()
  {
    if (this.adapter != null)
      this.adapter.onStop();
  }

  public void setAdapter(ListAdapter paramListAdapter)
  {
    getListView().setAdapter(paramListAdapter);
  }

  public void setChapterName(String paramString1, String paramString2, String paramString3)
  {
    this.chapNameView.setText(paramString1);
    this.chapNameView.setTextSize(IKnow.mSystemConfig.getBook_TextSize());
    if (paramString2 == null);
    this.mPid = paramString3;
  }
}